package com.cn.kabalifeuser.ui.service.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.solver.widgets.HelperWidget;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.ui.service.bean.BusinessListBean;
import com.cn.kabalifeuser.utils.GlideUtil;
import com.flyco.roundview.RoundTextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 晓林 on 2020/9/3.
 * function:
 */
public class BusinessAdapter extends BaseQuickAdapter<BusinessListBean.ResultBean.DataBean, BaseViewHolder> {
    public BusinessAdapter(int layoutResId, @Nullable List<BusinessListBean.ResultBean.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final BusinessListBean.ResultBean.DataBean item) {
        GlideUtil.ImageLoad(this.mContext, item.getCover_url(), helper.getView(R.id.cover_url));
        helper
                .setText(R.id.title, item.getTitle())
                .setText(R.id.tv_address_info, item.getAddress_info())
                .setText(R.id.tv_order_count, "单量：" + item.getOrder_count())
        ;
        RoundTextView textView = helper.getView(R.id.tv_juli);
        if (!TextUtils.isEmpty(item.getJuli())) {
            textView.setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_juli, item.getJuli());
        } else textView.setVisibility(View.GONE);

        String fraction = item.getFraction();
        ImageView xx1 = helper.getView(R.id.img_xx_1);
        ImageView xx2 = helper.getView(R.id.img_xx_2);
        ImageView xx3 = helper.getView(R.id.img_xx_3);
        ImageView xx4 = helper.getView(R.id.img_xx_4);
        ImageView xx5 = helper.getView(R.id.img_xx_5);
        if (fraction.equals("5.0")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_true);
            xx3.setImageResource(R.drawable.xx_true);
            xx4.setImageResource(R.drawable.xx_true);
            xx5.setImageResource(R.drawable.xx_true);
        } else if (fraction.equals("4.5")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_true);
            xx3.setImageResource(R.drawable.xx_true);
            xx4.setImageResource(R.drawable.xx_true);
            xx5.setImageResource(R.drawable.xx);
        } else if (fraction.equals("4.0")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_true);
            xx3.setImageResource(R.drawable.xx_true);
            xx4.setImageResource(R.drawable.xx_true);
            xx5.setImageResource(R.drawable.xx_false);
        } else if (fraction.equals("3.5")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_true);
            xx3.setImageResource(R.drawable.xx_true);
            xx4.setImageResource(R.drawable.xx);
            xx5.setImageResource(R.drawable.xx_false);
        } else if (fraction.equals("3.0")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_true);
            xx3.setImageResource(R.drawable.xx_true);
            xx4.setImageResource(R.drawable.xx_false);
            xx5.setImageResource(R.drawable.xx_false);
        } else if (fraction.equals("2.5")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_true);
            xx3.setImageResource(R.drawable.xx);
            xx4.setImageResource(R.drawable.xx_false);
            xx5.setImageResource(R.drawable.xx_false);
        } else if (fraction.equals("2.0")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_true);
            xx3.setImageResource(R.drawable.xx_false);
            xx4.setImageResource(R.drawable.xx_false);
            xx5.setImageResource(R.drawable.xx_false);
        } else if (fraction.equals("1.5")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx);
            xx3.setImageResource(R.drawable.xx_false);
            xx4.setImageResource(R.drawable.xx_false);
            xx5.setImageResource(R.drawable.xx_false);
        } else if (fraction.equals("1.0")) {
            xx1.setImageResource(R.drawable.xx_true);
            xx2.setImageResource(R.drawable.xx_false);
            xx3.setImageResource(R.drawable.xx_false);
            xx4.setImageResource(R.drawable.xx_false);
            xx5.setImageResource(R.drawable.xx_false);
        } else if (fraction.equals("0.5")) {
            xx1.setImageResource(R.drawable.xx);
            xx2.setImageResource(R.drawable.xx_false);
            xx3.setImageResource(R.drawable.xx_false);
            xx4.setImageResource(R.drawable.xx_false);
            xx5.setImageResource(R.drawable.xx_false);
        } else {
            xx1.setImageResource(R.drawable.xx_false);
            xx2.setImageResource(R.drawable.xx_false);
            xx3.setImageResource(R.drawable.xx_false);
            xx4.setImageResource(R.drawable.xx_false);
            xx5.setImageResource(R.drawable.xx_false);
        }

        List<String> mListStr = new ArrayList<>();
        for (int i = 0; i < item.getServices().size(); i++) {
            mListStr.add(item.getServices().get(i).getTitle());
        }
        RecyclerView rv_type_list = helper.getView(R.id.rv_type_list);
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(this.mContext);
        layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
        layoutManager1.setSmoothScrollbarEnabled(true);
        layoutManager1.setAutoMeasureEnabled(true);
        rv_type_list.setLayoutManager(layoutManager1);
        rv_type_list.setNestedScrollingEnabled(false);
        ServicesTypeTitleAdapter servicesTypeTitleAdapter = new ServicesTypeTitleAdapter(R.layout.list_item_type, mListStr);
        //给RecyclerView设置适配器
        rv_type_list.setAdapter(servicesTypeTitleAdapter);
    }
}
